#include "sys/Memory.h"
#include "sys/IO.h"
typedef enum{
    VIC_F_DEFAULT=0,
    VIC_F_FIFO,
    VIC_F_LRU,
    VIC_F_REFSHIFT, //额外引用位算法
    VIC_F_2CHANCE, //第二次机会算法
}VICTIM_FRAME_ALG;
static char SC_r[PHY_PAGE_NUM];//二次机会算法所用
void PR_UpdateFrame(unsigned ppn, int T){
    SC_r[ppn] = 1;
}
int victim_frame(int pid, int algorithm){
    //优先找空格
    for (int i=0;i<PHY_PAGE_NUM;++i){
        if (pid==-1 || frame_table[i].pid==pid){//查找目标内
            if (frame_table[i].VPN==-1)
                return i;
        }
    }

    //无空格再实现下列算法
    int vic = -1;
switch (algorithm)
{
    case VIC_F_DEFAULT:
    case VIC_F_2CHANCE:
        while (vic==-1){
            for (int i=0;i<PHY_PAGE_NUM;++i){
                if (pid==-1 || frame_table[i].pid==pid){//查找目标内
                    if (SC_r[i]){
                        SC_r[i]=0;
                    }else{
                        vic = i;
                        break;
                    }
                }
            }
        }
        break;
    case VIC_F_FIFO:
        
        break;
    default:
        break;
}
return vic;
}